/etc/netplan/00-installer-config.yaml

network:
  version: 2
  ethernets:
    eth18:
      addresses:
        - 192.168.2.101/24
      routes:
        - to: 0.0.0.0/0
          via: 192.168.2.1
      nameservers:
        addresses: [8.8.8.8,114.114.114.114]







network:
    version: 2
    renderer: NetworkManager
    ethernets:
        ens33: # 网卡名称
            dhcp4: no # 禁用动态IP分配，以便于下面添加静态IP、网关和DNS服务器的信息
            addresses: [192.168.2.101/24] # 静态ip地址
            gateway4: 192.168.2.2 # 网关
            nameservers:
                addresses: [8.8.8.8, 114.114.114.114] # dns服务器地址

network:
  version: 2
  renderer: networkd
  ethernets:
    enp18:
      dhcp4: no
      addresses: [192.168.2.101/24]
      gateway4: 192.168.2.1
      nameservers:
        addresses: [8.8.8.8,114.114.114.114]

ip route add default via 192.168.2.1

network:
  version: 2
  ethernets:
    ens18:
      dhcp4: no
      addresses: [192.168.2.240/24]
      gateway4: 192.168.2.2
      nameservers:
        addresses: [8.8.8.8,114.114.114.114]


cat > /etc/netplan/00-installer-config.yaml << EOF
network:
  ethernets:
    ens18:
      dhcp4: no
      # 设置静态IP地址及子网掩码
      addresses: [192.168.2.250/24]
      # 设置默认网关
      gateway4: 192.168.2.1
      nameservers:
       # 设置DNS服务器
        addresses: [114.114.114.114,8.8.8.8,8.8.4.4]

  version: 2
EOF
  version: 2
其生效的方法：
 netplan apply
systemctl restart systemd-networkd
